package com.meta.nd.filter.vo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.meta.nd.annotation.bo.FdDef;
import com.meta.nd.annotation.bo.NdDef;
import lombok.Data;
import org.springframework.util.StringUtils;

@Data
@JsonSerialize(using = FilterFdSerializer.class)
@JsonDeserialize(using = FilterFdDeserializer.class)
@NdDef(ndName = "filterConditionFdNd")
public class FilterFd {
    @FdDef("ndName")
    String ndName;
    @FdDef("fdName")
    String fdName;
    @FdDef("fdAlias")
    String fdAlias;
    String dataType;
    @FdDef("logicalOperator")
    String logicalOperator;
    Object value;
    @FdDef("fixedValue")
    String fixedValue;
    @FdDef("expression")
    String expression;
    @FdDef("serNo")
    int serNo;


    @JsonIgnore

    public String getFinalName(){
        if (!StringUtils.isEmpty(this.fdAlias))
            return this.fdAlias;

        return this.fdName;
    }

    public FilterFd(){
    }

    public FilterFd(String ndName, String fdName, String fdAlias, String logicalOperator, Object value){
        this.ndName = ndName;
        this.fdName = fdName;
        this.logicalOperator = logicalOperator;
        this.value = value;
    }
    public boolean isExpression(){
        return !StringUtils.isEmpty(this.expression);
    }
}
